You are a Java developer and would like to integrate e-mail functionality into your application, but you haven’t written anything related to e-mail stuff before. So here is a good place for getting started with e-mail programming in Java.

Like any other Java technologies, we need to pick up a library and understand its API before writing and testing some real code. Although the JRE/JDK does not include a built-in API for e-mail, Oracle provides an optional package called JavaMail which is probably the most popular framework for e-mail programming with Java technology. The JavaMail is also a part of JavaEE’s technology stack.

 

1. Official resources for JavaMail

Here are some official resources provided by Oracle for its JavaMail technology:

-          JavaMail Home page.

-          JavaMail Download page.

-          JavaMail Documentation.

-          JavaMail Specification.

To begin, download the latest distribution of JavaMail (which is JavaMail 1.6.2 at the time of writing this article). A JavaMail distribution comes with the following items:

-          License and copyright notices.

-          Release changes.

-          API documentation.

-          Demo Java source code.

-          Jar files for protocol-dependent implementation: imap.jar, pop3.jar, smtp.jar…

-          Binary of the JavaMail API included in mail.jar file. This jar file is a combination of all jar files above. So to use JavaMail, only the mail.jar file is required.

 

2. Using JavaMail library

To compile and run code that is using JavaMail, add the mail.jar file to compile classpath and runtime classpath.

If you are using Java 5 or earlier, you have to download the JavaBeans Activation Framework (JAF) and add activation.jar file to the classpath. The JAF is only included in JDK since Java 6.

If you use Maven, simply specify the following dependency for your project:

<dependency>
	<groupId>com.sun.mail</groupId>
	<artifactId>javax.mail</artifactId>
	<version>1.6.2</version>
</dependency>

 

3. Understanding of e-mail protocols: SMTP, IMAP and POP3

Because JavaMail is based on standard e-mail protocols like SMTP, IMAP, and POP3, it’s recommended to have basic understanding of how these protocols work, as well as advantages and disadvantages of each protocol. That would help you implement your code more efficiently. Here are the links for these protocols on Wikipedia:

-          Simple Mail Transfer Protocol.

-          Internet Message Access Protocol.

-          Post Office Protocol.

And finally, once you have grasped the stuff above, follow our series of tutorial on JavaMail technology:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#1Amit Kumar2016-09-22 04:05
I have a problem email sending
i want to submit contact form only what is the code for send only contact form

please help me
Quote